<template>
  <el-container>
    <el-header>
      <h3>后台管理系统</h3>
      <el-link type="primary" @click="logout">退出</el-link>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu :default-active="defaultActive" class="el-menu-vertical-demo" background-color=" #545c64"
          text-color="#fff" active-text-color="#ffd04b" unique-opened :collapse="isCollapse" router>
          <!-- 一级菜单 -->
          <el-submenu v-for="menu in menuList" :index="menu.index + ''" :key="menu.index">
            <template slot="title">
              <i :class="menu.icon"></i>
              <span slot="title">{{menu.name}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item v-for="menuItem in  menu.children" :index="'/' + menuItem.path" :key="menu.index"
              @click="setDefaultActive('/getUserList')">
              <i :class="menuItem.icon"></i>
              <span slot="title">{{menuItem.name}}</span>
            </el-menu-item>
          </el-submenu>

        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    name: 'Home',
    data() {
      return {
        isCollapse: false,
        defaultActive: '',
        menuList: []
      }
    },
    created() {
      this.getMenuList();
    },
    methods: {
      logout() {
        this.$router.push('/login')
      },
      setDefaultActive(path) {
        this.defaultActive = path
      },
      async getMenuList() {
        const {
          data: res
        } = await this.$axios.post('/api/getMenuList', {})
        console.log(res)
        this.menuList = res.result
      }
    }
  }
</script>
<style scoped>
  .el-container {
    height: 100%;
  }

  .el-header {
    background-color: rgb(84, 92, 100);
    color: #333;
    text-align: center;
    line-height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .el-aside {
    background-color: rgb(84, 92, 100);
    color: #333;
    /* text-align: center; */
    line-height: 200px;
  }

  .el-main {
    background-color: #fefefe;
    color: #333;
    text-align: center;
  }

  .el-menu {
    border-right: solid 0px #e6e6e6;
  }
</style>
